<?php
/**
* 
*/
class LoginView
{
	public $uName = "UserName";
	public $pWord = "pword";
	private $logIn = "LogsIn";
	private $logOut = "LogOut";
	private $rember = "remeber";
	
	const USER_LOGGED_IN = 1;
	const USER_NOT_LOGGED = 2;
	const USER_NOW_LOGGED = 3;
	const USER_PROB = 4;
	const DO_LOGG_IN = 5;
	const DO_LOGG_OUT = 6;
	// funktion som innehåller ett form 
	function DologinBox()
	{
		return 
			"<div> 
				<form method='get' action='index.php'>
					Username:
						<input type='text' name=' $this->uName' /><p></p>
					Password:
						<input type='password' name='$this->pWord' /><p></p>
					remeber me:
						 <input type='checkbox' name='$this->rember'/>
					<input type='submit' value='Login' name='$this->logIn'/>
				</form>
			</div>";
	}
	// funktion som innehåller en knapp
	function DoLogoutBox()
	{
		return 
				"<div> 
					<form name='form2' method='get' action='index.php'> 
						<input type='submit' value='Logout' name='$this->logOut'/> 
					</form>
				</div>";
	}
	// de två funktionerna nedan hämtar upp användar namnet och lösenordet
	function GetUserName()
	{
		if (isset($_GET[$this->uName]) == true)
		{
			return $_GET[$this->uName];
		}
		return null;
	}
	function GetPassword()
	{
		if (isset($_GET[$this->pWord]) == true)
		{
			return $_GET[$this->pWord];
		}
		return null;
	}
	function GetRemember()
	{
		if (isset($_GET[$this->rember]))
		{
			return true;
		}
		return false;
	}
	function doCookie($uName, $pWord)
	{
		setcookie($this->uName, $uName, time()+3600*24*7);
        setcookie($this->pWord,  $pWord, time()+3600*24*7);  
	}

	function eatCooks()
	{
		 // Tar bort cookie vid utloggning.
        setcookie($this->uName, '', time()-3600);
        unset($_COOKIE[$this->uName]);
        setcookie($this->pWord, '', time()-3600);
        unset($_COOKIE[$this->pWord]);
	}
	
	public function isCookieSet()
	{
		if(isset($_COOKIE[$this->uName])&& ($_COOKIE[$this->pWord]))
	  {
	  	return true;
	  }
	  else
	  {
	  	return false;
	  }
	}
	// kollar om man trycker på login eller logout 
	function TriedToLogIn()
	{ 
		if (isset($_GET[$this->logIn]) == true) 
		{
			return true;
		}
		return false;
	}
	function TriedToLogOut()
	{
		if (isset($_GET[$this->logOut])== true)
		{
			return true;
		}
		return false;
	}
	public function LoggInMess($status)
	{
		switch ($status) {
			case self::USER_LOGGED_IN:
				return "<p><i>You're logged in</i></p>";
				break;
				case self::USER_NOT_LOGGED:
				return "<p><i>You're not logged in</i></p>";
				break;
				case self::USER_NOW_LOGGED:
				return "<p><i>You are now logged in</i></p>";
				break;
				case self::USER_PROB:
				return "<p><i>Wrong username, password or whitespace!</i></p>";
				break;
				case self::DO_LOGG_IN:
				return "<h3>Logg in:</h3>";
				break;
				case self::DO_LOGG_OUT:
				return "<p><i>You did loggout:</i></p>";
			
			default:
				
				break;
		}
		
	}
	// shit
	public function UpLoad()
	{
		return '<form enctype="multipart/form-data" action="FileUpload.php" method="POST">
		Choose a file to upload: <input name="uploaded" type="file" /><br />
		<input type="submit" value="Upload File" />
		</form> <hr/>'.'<a href="uploads/">Visa uppladdade filer</a> <br/>';
	} 

}
?>

